package main

import "fmt"

/*
	验证用户名密码是否正确
	var userList = map[string]map[string]string{
		"root":{"password":"123456", "tel":"158xxxxxxxx"},
		"admin":{"password":"123456", "tel":"158xxxxxxxx"},
		"xiaoming":{"password":"123456", "tel":"158xxxxxxxx"}}
	输入用户名密码，进行验证，验证成功后，输出手机号码
*/

func main() {
	var userList = map[string]map[string]string{
		"root":{"password":"123456", "tel":"156xxxxxxxx"},
		"admin":{"password":"123456", "tel":"157xxxxxxxx"},
		"xiaoming":{"password":"123456", "tel":"158xxxxxxxx"}}
	fmt.Println("清输入用户名:")
	username := ""
	fmt.Scanf("%s",&username)
	fmt.Println("清输入密码:")
	password := ""
	fmt.Scanf("%s",&password)
	if login(username,password,userList) {
		fmt.Printf("登录成功")
	}else {
		fmt.Printf("登录失败")
	}

}

func login(username string, password string, list map[string]map[string]string) bool {
	for userName, userInfo := range list {
		if userName == username {
			if userInfo["password"] == password {
				fmt.Printf("%s的电话号码是%s\n",userName,userInfo["tel"])
				return true
			}
		}
	}
	fmt.Printf("没有%s该用户名\n",username)
	return false
}
